<?php

namespace app\admin\controller\workorder;

use app\common\controller\Backend;

/**
 * 工单评价管理
 */
class Evaluate extends Backend
{

    /**
     * Evaluate模型对象
     * @var \app\admin\model\workorder\Evaluate
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\workorder\Evaluate();
        $this->view->assign("starsList", $this->model->getStarsList());
        $this->view->assign("solvedList", $this->model->getSolvedList());
    }

    public function import()
    {
        parent::import();
    }

    /**
     * 查看
     */
    public function index()
    {
        // 当前是否为关联查询
        $this->relationSearch = true;
        // 设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model->with(['orders', 'user', 'category'])
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);

            foreach ($list as $row) {
                $row->getRelation('orders')->visible(['title']);
                $row->getRelation('user')->visible(['nickname']);
                $row->getRelation('category')->visible(['name']);
            }

            return json(["total" => $list->total(), "rows" => $list->items()]);
        }
        return $this->view->fetch();
    }

}
